*************************************************
***********REPLICATION DO FILE FOR***************
* Knutsen, Carl Henrik (2014)********************
* Income Growth and Revolutions******************
* Social Science Quarterly***********************

*clear
*use "M:\apostoc\data\SSQ.dta", clear

keep gwno country year urban01 pop1 domestic7 warno outcome gdppp growthgdppp oil_gas_value_2000 ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto westeurplusoffshots easteursov africass asiapac latam mideanafr Politynonanarchy logdur ythblgap wageshare dec92 dec93 dec94 dec95 dec96 dec97 dec98 dec99long
sort gwno year
xtset gwno year


*************************************************
********VARIABLE GENERATION**********************
*************************************************


**Generate urbaniz from Banks data
generate urbanpercent = 100*(urban01/pop1)
**log population from Banks
generate logpopBanks = ln(pop1*1000)
**generate log income
generate LNgdppp = ln(gdppp)

**Create dummy for Banks' revolution variable
generate banksrevolution = 1 if domestic7>0 &domestic7!=.
mvencode banksrevolution if domestic7==0, mv(0)

**generate dummies for leader exit based on Archigos, code 1 on years where at least on leader was terminated because of below-descirbed causes, only coded from 1919 onwards including 2004

**domestic popular protest no foreign support
generate popprotfs=.

replace popprotfs =1 if gwno==94 & year==1919

**Vietnam 1964 not coded bec of missing gwno
generate popprotnofs =.

replace popprotnofs =1 if gwno==373 & year==1992
replace popprotnofs =1 if gwno==771 & year==1990
replace popprotnofs =1 if gwno==145 & year==1946
replace popprotnofs =1 if gwno==484 & year==1963
replace popprotnofs =1 if gwno==437 & year==2000
replace popprotnofs =1 if gwno==130 & year==1966
replace popprotnofs =1 if gwno==130 & year==2000
replace popprotnofs =1 if gwno==92 & year==1944
replace popprotnofs =1 if gwno==372 & year==2003
replace popprotnofs =1 if gwno==90 & year==1944
replace popprotnofs =1 if gwno==41 & year==1990
replace popprotnofs =1 if gwno==310 & year==1956
replace popprotnofs =1 if gwno==630 & year==1979
replace popprotnofs =1 if gwno==580 & year==1972
replace popprotnofs =1 if gwno==770 & year==1969
replace popprotnofs =1 if gwno==840 & year==1986
replace popprotnofs =1 if gwno==290 & year==1970
replace popprotnofs =1 if gwno==360 & year==1989
replace popprotnofs =1 if gwno==732 & year==1960
replace popprotnofs =1 if gwno==230 & year==1919
replace popprotnofs =1 if gwno==230 & year==1931
replace popprotnofs =1 if gwno==625 & year==1964
replace popprotnofs =1 if gwno==800 & year==1973
replace popprotnofs =1 if gwno==101 & year==1958

**Yemen People's rep. 1978 not coded bec of missing gwno
generate rebelfs=.

replace rebelfs =1 if gwno==700 & year==2001
replace rebelfs =1 if gwno==355 & year==1944
replace rebelfs =1 if gwno==483 & year==1979
replace rebelfs =1 if gwno==710 & year==1945
replace rebelfs =1 if gwno==484 & year==1997
replace rebelfs =1 if gwno==41 & year==2004
replace rebelfs =1 if gwno==310 & year==1919
replace rebelfs =1 if gwno==812 & year==1975
replace rebelfs =1 if gwno==93 & year==1979
replace rebelfs =1 if gwno==230 & year==1939

**DRC 1997 and Yemen arab rep 1948 not coded bec of missing gwno
generate rebelnofs=.

replace rebelnofs =1 if gwno==700 & year==1929
replace rebelnofs =1 if gwno==700 & year==1992
replace rebelnofs =1 if gwno==700 & year==1996
replace rebelnofs =1 if gwno==339 & year==1924
replace rebelnofs =1 if gwno==615 & year==1992
replace rebelnofs =1 if gwno==305 & year==1934
replace rebelnofs =1 if gwno==373 & year==1993
replace rebelnofs =1 if gwno==145 & year==1952
replace rebelnofs =1 if gwno==811 & year==1975
replace rebelnofs =1 if gwno==482 & year==2003
replace rebelnofs =1 if gwno==483 & year==1982
replace rebelnofs =1 if gwno==483 & year==1990
replace rebelnofs =1 if gwno==710 & year==1949
replace rebelnofs =1 if gwno==581 & year==1975
replace rebelnofs =1 if gwno==94 & year==1919
replace rebelnofs =1 if gwno==94 & year==1948
replace rebelnofs =1 if gwno==40 & year==1959
replace rebelnofs =1 if gwno==530 & year==1991
replace rebelnofs =1 if gwno==950 & year==2000
replace rebelnofs =1 if gwno==372 & year==1992
replace rebelnofs =1 if gwno==90 & year==1920
replace rebelnofs =1 if gwno==205 & year==1922
replace rebelnofs =1 if gwno==740 & year==1932
replace rebelnofs =1 if gwno==367 & year==1919
replace rebelnofs =1 if gwno==660 & year==1989
replace rebelnofs =1 if gwno==450 & year==1990
replace rebelnofs =1 if gwno==70 & year==1920
replace rebelnofs =1 if gwno==95 & year==1931
replace rebelnofs =1 if gwno==520 & year==1991
replace rebelnofs =1 if gwno==702 & year==1992
replace rebelnofs =1 if gwno==500 & year==1986
replace rebelnofs =1 if gwno==101 & year==1950

mvencode popprotfs popprotnofs rebelfs rebelnofs if year>1918 & year<2005, mv(0)

generate exitrevolution = popprotfs+popprotnofs+rebelfs+rebelnofs

**generate variable "loss in war" based on correlates of war data Outcome==2 taken from BdM democratic peace. Value 1 for country-years where lost war (final year) and two following years, Germany coded from 1945 rather than 1939
**note that Hungary's loss in war, e.g., is result of revolution..endogeneity.

generate lossinwar=0
sort outcome gwno year
browse country gwno year warno outcome lossinwar

replace lossinwar =1 if gwno==70 &(year==1848 |year==1849 |year==1850)
replace lossinwar =1 if gwno==90 &(year==1885 |year==1886 |year==1887)
replace lossinwar =1 if gwno==91 &(year==1907 |year==1908 |year==1909)
replace lossinwar =1 if gwno==91 &(year==1969 |year==1970 |year==1971)
replace lossinwar =1 if gwno==92 &(year==1876 |year==1877 |year==1878)
replace lossinwar =1 if gwno==92 &(year==1907 |year==1908 |year==1909)
replace lossinwar =1 if gwno==130 &(year==1863 |year==1864 |year==1865)
replace lossinwar =1 if gwno==135 &(year==1883 |year==1884 |year==1885)
replace lossinwar =1 if gwno==145 &(year==1883 |year==1884 |year==1885)
replace lossinwar =1 if gwno==145 &(year==1935 |year==1936 |year==1937)
replace lossinwar =1 if gwno==150 &(year==1870 |year==1871 |year==1872)
replace lossinwar =1 if gwno==160 &(year==1852 |year==1853 |year==1854)
replace lossinwar =1 if gwno==160 &(year==1982 |year==1983 |year==1984)
replace lossinwar =1 if gwno==220 &(year==1867 |year==1868 |year==1869)
replace lossinwar =1 if gwno==220 &(year==1871 |year==1872 |year==1873)
replace lossinwar =1 if gwno==230 &(year==1823 |year==1824 |year==1825)
replace lossinwar =1 if gwno==230 &(year==1866 |year==1867 |year==1868)
replace lossinwar =1 if gwno==230 &(year==1898 |year==1899 |year==1900)
replace lossinwar =1 if gwno==260 &(year==1945 |year==1946 |year==1947)
replace lossinwar =1 if gwno==310 &(year==1919 |year==1920 |year==1921)
replace lossinwar =1 if gwno==310 &(year==1956 |year==1957 |year==1958)
replace lossinwar =1 if gwno==350 &(year==1897 |year==1898 |year==1899)
replace lossinwar =1 if gwno==350 &(year==1922 |year==1923 |year==1924)
replace lossinwar =1 if gwno==352 &(year==1974 |year==1975 |year==1976)
replace lossinwar =1 if gwno==355 &(year==1913 |year==1914 |year==1915)
replace lossinwar =1 if gwno==365 &(year==1856 |year==1857 |year==1858)
replace lossinwar =1 if gwno==365 &(year==1905 |year==1906 |year==1907)
replace lossinwar =1 if gwno==365 &(year==1920 |year==1921 |year==1922)
replace lossinwar =1 if gwno==365 &(year==1938 |year==1939 |year==1940)
replace lossinwar =1 if gwno==368 &(year==1920 |year==1921 |year==1922)
replace lossinwar =1 if gwno==375 &(year==1939 |year==1940 |year==1941)
replace lossinwar =1 if gwno==390 &(year==1848 |year==1849 |year==1850)
replace lossinwar =1 if gwno==390 &(year==1864 |year==1865 |year==1866)
replace lossinwar =1 if gwno==500 &(year==1979 |year==1980 |year==1981)
replace lossinwar =1 if gwno==520 &(year==1978 |year==1979 |year==1980)
replace lossinwar =1 if gwno==620 &(year==1979 |year==1980 |year==1981)
replace lossinwar =1 if gwno==645 &(year==1948 |year==1949 |year==1950)
replace lossinwar =1 if gwno==645 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==645 &(year==1991 |year==1992 |year==1993)
replace lossinwar =1 if gwno==651 &(year==1956 |year==1957 |year==1958)
replace lossinwar =1 if gwno==651 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==652 &(year==1948 |year==1949 |year==1950)
replace lossinwar =1 if gwno==652 &(year==1967 |year==1968 |year==1969)
replace lossinwar =1 if gwno==652 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==660 &(year==1948 |year==1949 |year==1950)
replace lossinwar =1 if gwno==663 &(year==1948 |year==1949 |year==1950)
replace lossinwar =1 if gwno==663 &(year==1967 |year==1968 |year==1969)
replace lossinwar =1 if gwno==663 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==710 &(year==1885 |year==1886 |year==1887)
replace lossinwar =1 if gwno==710 &(year==1895 |year==1896 |year==1897)
replace lossinwar =1 if gwno==710 &(year==1900 |year==1901 |year==1902)
replace lossinwar =1 if gwno==750 &(year==1962 |year==1963 |year==1964)
replace lossinwar =1 if gwno==750 &(year==1965 |year==1966 |year==1967)
replace lossinwar =1 if gwno==770 &(year==1971 |year==1972 |year==1973)
replace lossinwar =1 if gwno==800 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==811 &(year==1970 |year==1971 |year==1972)
replace lossinwar =1 if gwno==840 &(year==1973 |year==1974 |year==1975)
replace lossinwar =1 if gwno==900 &(year==1972 |year==1973 |year==1974)
sort country year
browse country year outcome lossinwar

**Costa Rica 1919 changed from 2 (only one with score >1) to 1.
replace exitrevolution =1 if gwno==94 & year==1919

**Some simple descriptives:
summarize domestic7 banksrevolution exitrevolution if gdppp!=. & growthgdppp!=.

correlate gdppp growthgdppp exitrevolution banksrevolution

mean exitrevolution if growthgdppp>0
mean exitrevolution if growthgdppp<0
generate l1growthgdppp = growthgdppp[_n-1]
generate avshortgrowth =(l1growthgdppp + growthgdppp)/2
mean exitrevolution if l1growthgdppp>0
mean exitrevolution if l1growthgdppp<0

mean domestic7 if growthgdppp>0
mean domestic7 if growthgdppp<0

mean domestic7 if l1growthgdppp>0
mean domestic7 if l1growthgdppp<0

mean banksrevolution if growthgdppp>0
mean banksrevolution if growthgdppp<0

mean banksrevolution if l1growthgdppp>0
mean banksrevolution if l1growthgdppp<0

**generate revolution avg globally
egen globalrevol=mean(banksrevolution), by (year)
egen globalrevolu=sum(banksrevolution), by (year)

**generate revolution avg by region, adjusted to exclude countries own revolutions
egen WER=sum(banksrevolution) if  westeurplusoffshots==1, by (year)
egen WE = sum(westeurplusoffshots) if  westeurplusoffshots==1, by (year)
generate WERA = (WER-banksrevolution)/(WE-1)

egen EER=sum(banksrevolution) if  easteursov==1, by (year)
egen EE = sum(easteursov) if  easteursov==1, by (year)
generate EERA = (EER-banksrevolution)/(EE-1)

egen AFR=sum(banksrevolution) if  africass==1, by (year)
egen AF = sum(africass) if  africass==1, by (year)
generate AFRA = (AFR-banksrevolution)/(AF-1)

egen ASR=sum(banksrevolution) if  asiapac==1, by (year)
egen AS = sum(asiapac) if  asiapac==1, by (year)
generate ASRA = (ASR-banksrevolution)/(AS-1)

egen LAR=sum(banksrevolution) if  latam==1, by (year)
egen LA = sum(latam) if  latam==1, by (year)
generate LARA = (LAR-banksrevolution)/(LA-1)

egen MER=sum(banksrevolution) if  mideanafr==1, by (year)
egen ME = sum(mideanafr) if  mideanafr==1, by (year)
generate MERA = (MER-banksrevolution)/(ME-1)

generate regionrev = WERA
replace regionrev = EERA if regionrev==.
replace regionrev = AFRA if regionrev==.
replace regionrev = ASRA if regionrev==.
replace regionrev = MERA if regionrev==.
replace regionrev = LARA if regionrev==.

browse country year regionrev banksrevolution

egen WEurrevol=mean(banksrevolution) if  westeurplusoffshots==1, by (year)
egen EEurrevol=mean(banksrevolution) if  easteursov==1, by (year)
egen Africarevol=mean(banksrevolution) if  africass==1, by (year)
egen Asiarevol=mean(banksrevolution) if  asiapac==1, by (year)
egen MENArevol=mean(banksrevolution) if  mideanafr==1, by (year)
egen Latamrevol=mean(banksrevolution) if  latam==1, by (year)

generate regionrevol = WEurrevol
replace regionrevol = EEurrevol if regionrevol==.
replace regionrevol = Africarevol if regionrevol==.
replace regionrevol = Asiarevol if regionrevol==.
replace regionrevol = MENArevol if regionrevol==.
replace regionrevol = Latamrevol if regionrevol==.

browse country year  globalrevol WEurrevol EEurrevol Africarevol Asiarevol MENArevol Latamrevol regionrevol

**generate revolution avg globally
egen globalrevolex=mean(exitrevolution), by (year)
**generate revolution avg by region
egen WEurrevolex=mean(exitrevolution) if  westeurplusoffshots==1, by (year)
egen EEurrevolex=mean(exitrevolution) if  easteursov==1, by (year)
egen Africarevolex=mean(exitrevolution) if  africass==1, by (year)
egen Asiarevolex=mean(exitrevolution) if  asiapac==1, by (year)
egen MENArevolex=mean(exitrevolution) if  mideanafr==1, by (year)
egen Latamrevolex=mean(exitrevolution) if  latam==1, by (year)

generate regionrevolex = WEurrevolex
replace regionrevolex = EEurrevolex if regionrevolex==.
replace regionrevolex = Africarevolex if regionrevolex==.
replace regionrevolex = Asiarevolex if regionrevolex==.
replace regionrevolex = MENArevolex if regionrevolex==.
replace regionrevolex = Latamrevolex if regionrevolex==.

browse country year  globalrevolex WEurrevolex EEurrevolex regionrevolex

generate ialevelgrowth = gdppp*growthgdppp
generate growthpositive = 1 if growthgdppp>0 & growthgdppp<10000
replace growthpositive =0 if growthgdppp<0.00000000001 & growthgdppp>-100000
generate iagrowthposlevel = growthpositive*gdppp

generate IAlngdpgrowth = LNgdppp*growthgdppp 
generate iagrowthposlnlevel = growthpositive*LNgdppp


generate oil_gas_value_2000pc = oil_gas_value_2000/(pop1*1000)
mean oil_gas_value_2000pc
generate logoilincome =ln(oil_gas_value_2000pc+1)

sort gwno year
by gwno: generate lLNgdppp = LNgdppp[_n-1] 
sort gwno year
by gwno: generate llogoilincome = logoilincome[_n-1] 
sort gwno year
generate iapolitygdp = LNgdppp*Politynonanarchy
by gwno: generate liapolitygdp = lLNgdppp*Politynonanarchy
sort gwno year


************************************************************
************************************************************
******************** MAIN ANALYSIS *************************
************************************************************
************************************************************

************************************
** Table 1 - Relative Frequencies **
************************************
mean banksrevolution if gdppp<1501 & gdppp>0 & growthgdppp>0
mean banksrevolution if gdppp<3001 & gdppp>1500 & growthgdppp>0
mean banksrevolution if gdppp<5001 & gdppp>3000 & growthgdppp>0
mean banksrevolution if gdppp<10001 & gdppp>5000 & growthgdppp>0
mean banksrevolution if gdppp>10000 & gdppp < 100000 & growthgdppp>0

mean banksrevolution if gdppp<1501 & gdppp>0 & growthgdppp<0
mean banksrevolution if gdppp<3001 & gdppp>1500 & growthgdppp<0
mean banksrevolution if gdppp<5001 & gdppp>3000 & growthgdppp<0
mean banksrevolution if gdppp<10001 & gdppp>5000 & growthgdppp<0
mean banksrevolution if gdppp>10000 & gdppp < 100000 & growthgdppp<0

mean exitrevolution if gdppp<1501 & gdppp>0 & growthgdppp>0
mean exitrevolution if gdppp<3001 & gdppp>1500 & growthgdppp>0
mean exitrevolution if gdppp<5001 & gdppp>3000 & growthgdppp>0
mean exitrevolution if gdppp<10001 & gdppp>5000 & growthgdppp>0
mean exitrevolution if gdppp>10000 & gdppp < 100000 & growthgdppp>0

mean exitrevolution if gdppp<1501 & gdppp>0 & growthgdppp<0
mean exitrevolution if gdppp<3001 & gdppp>1500 & growthgdppp<0
mean exitrevolution if gdppp<5001 & gdppp>3000 & growthgdppp<0
mean exitrevolution if gdppp<10001 & gdppp>5000 & growthgdppp<0
mean exitrevolution if gdppp>10000 & gdppp < 100000 & growthgdppp<0
 
*******************************************************************************************************************************************************
** Table 2 - Panel Data Logit Models: At least one revolutionary attempt or at least one successful revolution as dependent variables p. 9-10, 12-13 **
*******************************************************************************************************************************************************

xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b
xtlogit banksrevolution LNgdppp iapolitygdp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store c
xtlogit exitrevolution LNgdppp iapolitygdp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d
xtlogit banksrevolution LNgdppp  logoilincome growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store e
xtlogit exitrevolution LNgdppp  logoilincome growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

***********************
* Marginsplots, p. 11 *
*********************** 
**Re-running Model I
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
* First hypothetical case (Polity = -10)
margins, at((mean) _all lossinwar=0 regionrevolex=0 LNgdppp=9.210 urbanpercent=33.33 Politynonanarchy=-10 logdur=2.398 logpopBanks=15.425 growthgdppp=(-5 -4 -3 -2 -1 0 1 2 3 4 5)) predict(pu0) 

* Second hypothetical case (Polity = 10)
margins, at((mean) _all lossinwar=0 regionrevolex=0 LNgdppp=9.210 urbanpercent=33.33 Politynonanarchy=10 logdur=2.398 logpopBanks=15.425 growthgdppp=(-5 -4 -3 -2 -1 0 1 2 3 4 5)) predict(pu0) 

* Third hypothetical case, (Polity = -10; Income reduced to 5,000 USD)
margins, at((mean) _all lossinwar=0 regionrevolex=0 LNgdppp=8.517 urbanpercent=33.33 Politynonanarchy=-10 logdur=2.398 logpopBanks=15.425 growthgdppp=(-5 -4 -3 -2 -1 0 1 2 3 4 5)) predict(pu0) 

********************************
** SENSITIVITY ANALYSIS p. 11 **
********************************

* Sens 1 - drop LNgdppp
xtlogit banksrevolution growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 2 - drop growthgdppp
xtlogit banksrevolution LNgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 3 - drop Politynonanarchy
xtlogit banksrevolution LNgdppp growthgdppp logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 4 - drop logdur
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 5 - drop lossinwar 
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 6 - drop logpopBanks
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 7 - drop urbanpercent
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 8 - drop regionrevolex
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 9 - drop ethnic fractionalization
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Sens 10 - drop religious variables
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac, re
estimates store e

* Changing the revolutionary climate measure from being based on succesful to attempted revolutions, p. 11
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevol, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevol ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

*  Substituting growth variable with growth dummy, p. 11
xtlogit banksrevolution LNgdppp growthpositive Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthpositive Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b

* Different specifications of growth, p. 11
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit banksrevolution LNgdppp l1growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store b
xtlogit banksrevolution LNgdppp avshortgrowth Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store c
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d
xtlogit exitrevolution LNgdppp l1growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store e
xtlogit exitrevolution LNgdppp avshortgrowth Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Controlling for 1) youth bulges and 2) income inequality, p. 11

* Youth bulges
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ythblgap, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ythblgap ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b

* Income inequality
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex wageshare, fe
estimates store c
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex wageshare ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d

* Including decade dummmies in both models and region dummies only for Model 2, p. 11 (NB: There is a typo in the paper at p 11. Region dummies are _not_ included with Model 1 but _only_ for Model 2!!) 
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex dec92 dec93 dec94 dec95 dec96 dec97 dec98 dec99long, fe
estimates store e
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ythblgap ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto dec92 dec93 dec94 dec95 dec96 dec97 dec98 dec99long, re
estimates store f
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto easteursov africass asiapac mideanafr latam, re
estimates store g
estout a b c d e f g, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Including lagged dependent variable in the model, p. 11-12
generate l1banksrevolution = banksrevolution[_n-1]
generate l1exitrevolution = exitrevolution[_n-1]
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex l1banksrevolution, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex l1banksrevolution ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b

* Linear fixed effects model on the number of revolutionary attempts, p. 12
xtreg domestic7 LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store c

* Substituting panel logit models with probit models, p. 12
xtprobit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, re
estimates store d
xtprobit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store e

* Substituting standard logit models with errors clustered on country, p. 12
logit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, cluster(gwno)
estimates store f

* Income level a year before growth, p. 12
generate l1LNgdppp = LNgdppp[_n-1] if gwno == gwno[_n-1]
xtlogit banksrevolution l1LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store g
xtlogit exitrevolution l1LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store h
estout a b c d e f g h, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)
**** Testing politysquared****:
generate polplus= Politynonanarchy+11
generate polsq =polplus^2
* Running basic models from Table 2 first
xtlogit banksrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b
* Then including polity squared in the main models
xtlogit banksrevolution LNgdppp growthgdppp polsq Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store c
xtlogit exitrevolution LNgdppp growthgdppp polsq Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store d
estout a b c d, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Including interaction term polity * growth in order to test H1a, p. 12
generate iapolgrowth = Politynonanarchy*growthgdppp
xtlogit banksrevolution LNgdppp iapolgrowth growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp iapolgrowth growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b
estout a b, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Including interaction growth * GDP in order to test H3, p. 13
generate ialevgrowth=LNgdppp*growthgdppp
xtlogit banksrevolution LNgdppp ialevgrowth growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store a
xtlogit exitrevolution LNgdppp ialevgrowth growthgdppp Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store b
estout a b, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

***Preparing for analysis of J-curves and DDPs
generate l1gdppp = gdppp[_n-1]
generate l2gdppp = gdppp[_n-2]
generate l3gdppp = gdppp[_n-3]
generate l4gdppp = gdppp[_n-4]
generate l5gdppp = gdppp[_n-5]
generate l6gdppp = gdppp[_n-6]
generate l7gdppp = gdppp[_n-7]
generate l8gdppp = gdppp[_n-8]
generate l9gdppp = gdppp[_n-9]
generate l10gdppp = gdppp[_n-10]
generate l11gdppp = gdppp[_n-11]
generate l12gdppp = gdppp[_n-12]
generate l13gdppp = gdppp[_n-13]
generate l14gdppp = gdppp[_n-14]
generate l15gdppp = gdppp[_n-15]
generate l16gdppp = gdppp[_n-16]
generate l17gdppp = gdppp[_n-17]
generate l18gdppp = gdppp[_n-18]
generate l19gdppp = gdppp[_n-19]
generate l20gdppp = gdppp[_n-20]
generate l21gdppp = gdppp[_n-21]
generate l22gdppp = gdppp[_n-22]
generate l23gdppp = gdppp[_n-23]
generate l24gdppp = gdppp[_n-24]
generate l25gdppp = gdppp[_n-25]
generate l26gdppp = gdppp[_n-26]
generate l27gdppp = gdppp[_n-27]
generate l28gdppp = gdppp[_n-28]
generate l29gdppp = gdppp[_n-29]
generate l30gdppp = gdppp[_n-30]

generate LNgdppp_l15 = ln(l15gdppp)
generate LNgdppp_l20 = ln(l20gdppp)
generate LNgdppp_l25 = ln(l25gdppp)

generate shortgrowth2 = 100*((gdppp/l2gdppp)^(1/2)-1)
generate shortgrowth3 = 100*((gdppp/l2gdppp)^(1/3)-1)
generate longgrowth15_1 = 100*((l1gdppp/l16gdppp)^(1/15)-1)
generate longgrowth15_2 = 100*((l2gdppp/l17gdppp)^(1/15)-1)
generate longgrowth20_1 = 100*((l1gdppp/l21gdppp)^(1/20)-1)
generate longgrowth20_2 = 100*((l2gdppp/l22gdppp)^(1/20)-1)
generate longgrowth25_1 = 100*((l1gdppp/l26gdppp)^(1/25)-1)
generate longgrowth25_2 = 100*((l2gdppp/l27gdppp)^(1/25)-1)

***Generating different specifications of J-CURVES and DDP Patterns
generate modestJcurve1_15 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth15_1>3 & longgrowth15_1<3000
generate starkJcurve1_15 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth15_1>5 & longgrowth15_1<3000
mvencode modestJcurve1_15 starkJcurve1_15 if year>1918 & year<2005 & growthgdppp!=. & longgrowth15_1!=., mv(0)

generate modestdepcurve1_15 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth15_1<1 & longgrowth15_1>-3000 & growthgdppp<longgrowth15_1
generate starkdepcurve1_15 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth15_1<0 & longgrowth15_1>-3000 & growthgdppp<longgrowth15_1
mvencode modestdepcurve1_15 starkdepcurve1_15 if year>1918 & year<2005 & growthgdppp!=. & longgrowth15_1!=., mv(0)

generate modestJcurve1_20 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth20_1>3 & longgrowth20_1<3000
generate modestddepcurve1_20 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth20_1<1 & longgrowth20_1>-3000 & growthgdppp<longgrowth15_1
mvencode modestJcurve1_20 modestddepcurve1_20 if year>1918 & year<2005 & growthgdppp!=. & longgrowth20_1!=., mv(0)

generate modestJcurve1_25 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth25_1>3 & longgrowth25_1<3000
generate modestddepcurve1_25 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth25_1<1 & longgrowth25_1>-3000 & growthgdppp<longgrowth15_1
mvencode modestJcurve1_25 modestddepcurve1_25 if year>1918 & year<2005 & growthgdppp!=. & longgrowth25_1!=., mv(0)

****NB: The above were the different curves that were tested for the paper.

****************************************************************************************************************************************************************************
***After publication, I found that I had made a coding mistake for the 20 and 25 year DDP patterns that were used for robustness testing (these were not reported in tables)
* this mistake related to the requirement that the long-term growth should be higher than the short term growth; 
*(due to copy-pasting without sufficient attention to editing) I continued to use 15 years as basis for that requirement (see end of lines 602 and 606)
*The correct code should rather be
*
* for line 602:
*generate modestddepcurve1_20 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth20_1<1 & longgrowth20_1>-3000 & growthgdppp<longgrowth15_1
*
*********and********
*
*for line 606:
*generate modestddepcurve1_25 =1 if growthgdppp<0 &growthgdppp>-1000 & longgrowth25_1<1 & longgrowth25_1>-3000 & growthgdppp<longgrowth15_1
*
*when running the robustness tests on these corrected DDP variables, the results for the DDP pattern on revolution attempts and successful revolutions are somewhat stronger
****************************************************************************************************************************************************************************


*****************************************************************************
** Table 3 - J-Curves and Decromental Deprivation Patterns (...), p. 13-16 ** 
*****************************************************************************
* J-curve, 15 year
xtlogit banksrevolution modestJcurve1_15, fe
estimates store a
xtlogit exitrevolution modestJcurve1_15, re
estimates store b
xtlogit banksrevolution modestJcurve1_15 growthgdppp, fe
estimates store c
xtlogit exitrevolution modestJcurve1_15 growthgdppp, re
estimates store d
xtlogit banksrevolution modestJcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store e
xtlogit exitrevolution modestJcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store f

* DDP, 15 year
xtlogit banksrevolution modestdepcurve1_15, fe
estimates store g
xtlogit exitrevolution modestdepcurve1_15, re
estimates store h
xtlogit banksrevolution modestdepcurve1_15 growthgdppp, fe
estimates store i
xtlogit exitrevolution modestdepcurve1_15 growthgdppp, re
estimates store j
xtlogit banksrevolution modestdepcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex, fe
estimates store k
xtlogit exitrevolution modestdepcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto, re
estimates store l
estout a b c d e f g h i j k l, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

***************************
* Extra robustness checks *
***************************

* J-curve, 20 year
xtlogit banksrevolution modestJcurve1_20, fe
estimates store a
xtlogit exitrevolution modestJcurve1_20, re
estimates store b
xtlogit banksrevolution modestJcurve1_20 growthgdppp, fe
estimates store c
xtlogit exitrevolution modestJcurve1_20 growthgdppp, re
estimates store d
xtlogit banksrevolution modestJcurve1_20 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_e==1, fe
estimates store e
xtlogit exitrevolution modestJcurve1_20 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* J-curve, 25 year
xtlogit banksrevolution modestJcurve1_25, fe
estimates store a
xtlogit exitrevolution modestJcurve1_25, re
estimates store b
xtlogit banksrevolution modestJcurve1_25 growthgdppp, fe
estimates store c
xtlogit exitrevolution modestJcurve1_25 growthgdppp, re
estimates store d
xtlogit banksrevolution modestJcurve1_25 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_e==1, fe
estimates store e
xtlogit exitrevolution modestJcurve1_25 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* DDP, 20 year
xtlogit banksrevolution modestddepcurve1_20, fe
estimates store a
xtlogit exitrevolution modestddepcurve1_20, re
estimates store b
xtlogit banksrevolution modestddepcurve1_20 growthgdppp, fe
estimates store c
xtlogit exitrevolution modestddepcurve1_20 growthgdppp, re
estimates store d
xtlogit banksrevolution modestddepcurve1_20 growthgdppp LNgdppp_l20 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_a==1, fe
estimates store e
xtlogit exitrevolution modestddepcurve1_20 growthgdppp LNgdppp_l20 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* DDP, 25 year
xtlogit banksrevolution modestddepcurve1_25, fe
estimates store a
xtlogit exitrevolution modestddepcurve1_25, re
estimates store b
xtlogit banksrevolution modestddepcurve1_25 growthgdppp, fe
estimates store c
xtlogit exitrevolution modestddepcurve1_25 growthgdppp, re
estimates store d
xtlogit banksrevolution modestddepcurve1_25 growthgdppp LNgdppp_l25 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_a==1, fe
estimates store e
xtlogit exitrevolution modestddepcurve1_25 growthgdppp LNgdppp_l25 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Stark J-curve
xtlogit banksrevolution starkJcurve1_15, fe
estimates store a
xtlogit exitrevolution starkJcurve1_15, re
estimates store b
xtlogit banksrevolution starkJcurve1_15 growthgdppp, fe
estimates store c
xtlogit exitrevolution starkJcurve1_15 growthgdppp, re
estimates store d
xtlogit banksrevolution starkJcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_e==1, fe
estimates store e
xtlogit exitrevolution starkJcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

* Stark DDP
xtlogit banksrevolution starkdepcurve1_15, fe
estimates store a
xtlogit exitrevolution starkdepcurve1_15, re
estimates store b
xtlogit banksrevolution starkdepcurve1_15 growthgdppp, fe
estimates store c
xtlogit exitrevolution starkdepcurve1_15 growthgdppp, re
estimates store d
xtlogit banksrevolution starkdepcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex if _est_e==1, fe
estimates store e
xtlogit exitrevolution starkdepcurve1_15 growthgdppp LNgdppp_l15 Politynonanarchy logdur lossinwar logpopBanks urbanpercent regionrevolex ethfrac sunni shia catholic protestanglic orthodox hindu budhkonfutaoshinto if _est_f==1, re
estimates store f
estout a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style (fixed)

*
*
*
*
* End
*
*
*
*
